from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-08-19 14:03:23.523602
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 19, Aug, 2022
Time: 14:03:32
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.1575
Nobs: 753.000 HQIC: -50.4973
Log likelihood: 9566.24 FPE: 9.48081e-23
AIC: -50.7102 Det(Omega_mle): 8.41936e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.296314 0.055143 5.374 0.000
L1.Burgenland 0.108020 0.036646 2.948 0.003
L1.Kärnten -0.106928 0.019434 -5.502 0.000
L1.Niederösterreich 0.208107 0.076457 2.722 0.006
L1.Oberösterreich 0.107431 0.074428 1.443 0.149
L1.Salzburg 0.254657 0.039164 6.502 0.000
L1.Steiermark 0.037665 0.051075 0.737 0.461
L1.Tirol 0.108500 0.041373 2.622 0.009
L1.Vorarlberg -0.060136 0.035544 -1.692 0.091
L1.Wien 0.051059 0.066066 0.773 0.440
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.063162 0.114902 0.550 0.583
L1.Burgenland -0.033608 0.076359 -0.440 0.660
L1.Kärnten 0.046932 0.040494 1.159 0.246
L1.Niederösterreich -0.175576 0.159314 -1.102 0.270
L1.Oberösterreich 0.401025 0.155087 2.586 0.010
L1.Salzburg 0.288738 0.081606 3.538 0.000
L1.Steiermark 0.106268 0.106425 0.999 0.318
L1.Tirol 0.314113 0.086210 3.644 0.000
L1.Vorarlberg 0.026244 0.074063 0.354 0.723
L1.Wien -0.029595 0.137663 -0.215 0.830
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189757 0.028338 6.696 0.000
L1.Burgenland 0.089817 0.018832 4.769 0.000
L1.Kärnten -0.008824 0.009987 -0.884 0.377
L1.Niederösterreich 0.260419 0.039291 6.628 0.000
L1.Oberösterreich 0.135279 0.038249 3.537 0.000
L1.Salzburg 0.045721 0.020126 2.272 0.023
L1.Steiermark 0.018476 0.026247 0.704 0.481
L1.Tirol 0.093553 0.021262 4.400 0.000
L1.Vorarlberg 0.058445 0.018266 3.200 0.001
L1.Wien 0.118537 0.033951 3.491 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107349 0.028846 3.721 0.000
L1.Burgenland 0.046373 0.019170 2.419 0.016
L1.Kärnten -0.014384 0.010166 -1.415 0.157
L1.Niederösterreich 0.192170 0.039995 4.805 0.000
L1.Oberösterreich 0.292471 0.038934 7.512 0.000
L1.Salzburg 0.111164 0.020487 5.426 0.000
L1.Steiermark 0.102538 0.026718 3.838 0.000
L1.Tirol 0.108951 0.021643 5.034 0.000
L1.Vorarlberg 0.069913 0.018593 3.760 0.000
L1.Wien -0.017329 0.034560 -0.501 0.616
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.128121 0.052305 2.449 0.014
L1.Burgenland -0.050685 0.034760 -1.458 0.145
L1.Kärnten -0.040603 0.018433 -2.203 0.028
L1.Niederösterreich 0.171149 0.072522 2.360 0.018
L1.Oberösterreich 0.139786 0.070598 1.980 0.048
L1.Salzburg 0.288580 0.037148 7.768 0.000
L1.Steiermark 0.033820 0.048446 0.698 0.485
L1.Tirol 0.162475 0.039244 4.140 0.000
L1.Vorarlberg 0.100855 0.033714 2.991 0.003
L1.Wien 0.068540 0.062666 1.094 0.274
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.056404 0.041729 1.352 0.176
L1.Burgenland 0.040470 0.027731 1.459 0.144
L1.Kärnten 0.050323 0.014706 3.422 0.001
L1.Niederösterreich 0.220924 0.057858 3.818 0.000
L1.Oberösterreich 0.285510 0.056323 5.069 0.000
L1.Salzburg 0.045101 0.029637 1.522 0.128
L1.Steiermark -0.001250 0.038650 -0.032 0.974
L1.Tirol 0.147444 0.031309 4.709 0.000
L1.Vorarlberg 0.072691 0.026897 2.703 0.007
L1.Wien 0.083179 0.049995 1.664 0.096
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.177984 0.049864 3.569 0.000
L1.Burgenland -0.003928 0.033137 -0.119 0.906
L1.Kärnten -0.062104 0.017573 -3.534 0.000
L1.Niederösterreich -0.080351 0.069137 -1.162 0.245
L1.Oberösterreich 0.193668 0.067303 2.878 0.004
L1.Salzburg 0.057303 0.035414 1.618 0.106
L1.Steiermark 0.231595 0.046185 5.015 0.000
L1.Tirol 0.496207 0.037412 13.263 0.000
L1.Vorarlberg 0.047040 0.032141 1.464 0.143
L1.Wien -0.055119 0.059741 -0.923 0.356
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.165335 0.057426 2.879 0.004
L1.Burgenland -0.010709 0.038163 -0.281 0.779
L1.Kärnten 0.067138 0.020238 3.317 0.001
L1.Niederösterreich 0.206030 0.079622 2.588 0.010
L1.Oberösterreich -0.069019 0.077510 -0.890 0.373
L1.Salzburg 0.210644 0.040785 5.165 0.000
L1.Steiermark 0.116697 0.053189 2.194 0.028
L1.Tirol 0.071115 0.043086 1.651 0.099
L1.Vorarlberg 0.121883 0.037015 3.293 0.001
L1.Wien 0.122519 0.068801 1.781 0.075
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.360366 0.032984 10.925 0.000
L1.Burgenland 0.006992 0.021920 0.319 0.750
L1.Kärnten -0.023674 0.011624 -2.037 0.042
L1.Niederösterreich 0.214581 0.045733 4.692 0.000
L1.Oberösterreich 0.195352 0.044519 4.388 0.000
L1.Salzburg 0.044957 0.023426 1.919 0.055
L1.Steiermark -0.015614 0.030551 -0.511 0.609
L1.Tirol 0.105653 0.024748 4.269 0.000
L1.Vorarlberg 0.072741 0.021261 3.421 0.001
L1.Wien 0.040533 0.039518 1.026 0.305
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.039998 0.144569 0.193184 0.154036 0.122689 0.108416 0.065202 0.220963
Kärnten 0.039998 1.000000 -0.005663 0.133219 0.039784 0.095443 0.431518 -0.053049 0.098528
Niederösterreich 0.144569 -0.005663 1.000000 0.336915 0.144529 0.297648 0.101406 0.181505 0.317176
Oberösterreich 0.193184 0.133219 0.336915 1.000000 0.227262 0.330553 0.173203 0.166978 0.263780
Salzburg 0.154036 0.039784 0.144529 0.227262 1.000000 0.145319 0.117055 0.145806 0.126364
Steiermark 0.122689 0.095443 0.297648 0.330553 0.145319 1.000000 0.149268 0.136989 0.076673
Tirol 0.108416 0.431518 0.101406 0.173203 0.117055 0.149268 1.000000 0.113618 0.147018
Vorarlberg 0.065202 -0.053049 0.181505 0.166978 0.145806 0.136989 0.113618 1.000000 0.003814
Wien 0.220963 0.098528 0.317176 0.263780 0.126364 0.076673 0.147018 0.003814 1.000000